#!/usr/bin/python
# -*- coding: UTF-8 -*-

################################################################################
#
# Copyright (c) 2020 openEuler.org, Inc. All Rights Reserved
#
################################################################################
"""
Control task

Authors: xiaojianghui
Date:    10/22/2020 11:01 AM
"""

import apscheduler.schedulers.background as background
from controller import taskcontroller


def timertask():
    """
    Scheduled tasks summary
    :return:None
    """
    try:
        scheduler = background.BackgroundScheduler(job_defaults={'max_instances': 200})
        # Add tasks
        # Warehouse, organization, and owner correspondence timing task
        scheduler.add_job(taskcontroller.gwcontroller, 'cron', day_of_week='0-6', hour=0, minute=2)
        # Manual CVE data entry timing task
        scheduler.add_job(taskcontroller.runtabletask, 'interval', minutes=40)
        # Error data export and email sending timing task
        scheduler.add_job(taskcontroller.toexcelcontroller, 'cron', day_of_week='0-6', hour=7, minute=30)
        # Package name correspondence relationship timing task
        scheduler.add_job(taskcontroller.runmappeingtask, 'cron', day_of_week='0-6', hour=7, minute=30)
        # Delete ,iles timed tasks that are more than one month old
        scheduler.add_job(taskcontroller.rundelfiletask, 'cron', day_of_week='0-6', hour=9, minute=30)
        # issue record email feedback
        scheduler.add_job(taskcontroller.run_issue_record_task, 'cron', day_of_week='0-6', hour=7, minute=30)
        # analysis the table package whitelist
        scheduler.add_job(taskcontroller.run_whiltlist_task, 'interval', hours=2)
        # parsing the table package_committer_excels
        scheduler.add_job(taskcontroller.run_package_committer_task, 'interval', hours=1)
        # Parse the issue statistics recipient list
        # scheduler.add_job(taskcontroller.issue_statistics_email_task, 'cron', day_of_week='0-6', hour=5, minute=30)
        # Complete the template information of the issue with the data on the CVE official website
        scheduler.add_job(taskcontroller.supplement_cve_task, 'interval', minutes=33)
        scheduler.add_job(taskcontroller.long_supplement_cve_task, 'cron', day_of_week='0-6', hour=1, minute=30)
        # Parse opengauss yaml file
        scheduler.add_job(taskcontroller.parse_opengauss_yaml_task, 'cron', day_of_week='0-6', hour=2, minute=30)
        # Parse the yaml file of mindspore
        scheduler.add_job(taskcontroller.parse_mindspore_yaml_task, 'cron', day_of_week='0-6', hour=3, minute=30)
        # Parse the yaml file of openLooKeng
        # scheduler.add_job(taskcontroller.parse_openlookeng_yaml_task, 'cron', day_of_week='0-6', hour=4, minute=30)
        scheduler.start()
    except SystemExit as err:
        print("Err:", err)
